package ufo


import java.io.{ByteArrayOutputStream, ObjectOutputStream, ObjectInputStream, ByteArrayInputStream}

trait SerializedIndirection {
  def serialize[T](obj : T) : T = {
    val out = new ByteArrayOutputStream()
    val oo = new ObjectOutputStream(out)
    oo.writeObject(obj)
    oo.flush

    val in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray))
    in.readObject.asInstanceOf[T]
  }
}